package collection;

import java.util.ArrayList;
import java.util.List;
import java.util.SortedSet;
import java.util.TreeSet;

public class SortedSetDemo {

	public static void main(String[] args) {
		SortedSet<String> set = new TreeSet<String>();
		set.add("A");
		set.add("Y");
		set.add("K");
		set.add("M");
		set.add("D");
		System.out.println("Initial set: " + set);
				
		System.out.println("First: " + set.first());
		System.out.println("Last: " + set.last());
		System.out.println("HeadSet from 'K':" + set.headSet("K"));
		System.out.println("TailSet from 'K':" + set.tailSet("K"));
		System.out.println("SubSet between 'D' & 'M':" + set.subSet("D", "M"));
		System.out.println("SubSet between 'D' & 'M':" + set.subSet("D", "L"));
		
		List<String> list = new ArrayList<String>();
		list.add("A");
		list.add("D");
		list.add("K");
		set.retainAll(list);
		System.out.println("After retainAll['A','D','K']:" + set);
		set.removeAll(list);
		System.out.println("After removeAll['A','D','K']:" + set);
		System.out.println("Comparator: " + set.comparator());
	}
	
}
